package com.bangdream.michelia.view.fragment.main.curriculum;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.andview.refreshview.XRefreshView;
import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.courses.CourseInfoBean;
import com.bangdream.michelia.entity.courses.CoursesBean;
import com.bangdream.michelia.presenter.base.BasePresenter;
import com.bangdream.michelia.utils.L;
import com.bangdream.michelia.view.activity.live.LiveDetails;
import com.bangdream.michelia.view.fragment.currency.BaseFragment;
import com.zzhoujay.richtext.ImageHolder;
import com.zzhoujay.richtext.RichText;

/**
 * @date on 2018/7/23 17:04
 * @email 909732184@qq.com
 * 课程详情-介绍
 */
public class CurriculumDetailsIntroduce extends BaseFragment {
    private View view;
    private XRefreshView refreshView;
    private CourseInfoBean data;
    private TextView tvTitle, tvText, tvHtmlText;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.curriculum_introduce, container, false);
        RichText.initCacheDir(getActivity());

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    @Override
    public BasePresenter createPresenter() {
        return null;
    }

    private void initView() {
        if (getArguments() != null) {
            data = getArguments().getParcelable("data");
        }
        refreshView = view.findViewById(R.id.refreshView);
        refreshView.setPullRefreshEnable(false);
        refreshView.setPullLoadEnable(false);
        tvTitle = view.findViewById(R.id.tvTitle);
        tvText = view.findViewById(R.id.tvText);
        tvHtmlText = view.findViewById(R.id.tvHtmlText);
        setViewData(data);
    }

    private void setViewData(CourseInfoBean data) {
        this.data = data;
        if (data == null)
            return;
        L.d(data.toString());
        tvTitle.setText(data.getName());
        RichText.from(data.getIntroduction()+"")
                .autoPlay(true) // gif图片是否自动播放
                .scaleType(ImageHolder.ScaleType.center) // 图片缩放方式
                .size(ImageHolder.MATCH_PARENT, ImageHolder.WRAP_CONTENT) // 图片占位区域的宽高
                .into(tvHtmlText); // 设置目标TextView

    }
}
